import upperFirst from 'lodash/upperFirst';
import camelCase from 'lodash/camelCase';
import { App } from 'vue';

export const linkTo = (url = '', container = '#pjax-container') => {
  window.$.pjax({
    url,
    container
  });
};

export const initPage = (app: App, modules) => {
  return new Promise(async (resolve) => {
    for (const pathName in modules) {
      await modules[pathName]().then((mod) => {
        const name = pathName.split('Pages/')[1].replace(/\.\w+$/, '');
        const componentName = upperFirst(camelCase(name));
        app.component(componentName, mod.default);
      });
    }
    resolve(app);
  });
};
